# -*- coding: utf-8 -*-
# @Time    : 2020/7/17 10:30
# @Author  : ZhaoHexin
# @File    : EncodeSso.py
# @Description  : 加密sso文件

import os
from CreateSsoFile.BasicMethod import BasicMethod
from config import InfoConfig


class EncodeSso:
    def __init__(self):
        self.path = InfoConfig.path
        self.encode_path = InfoConfig.encryption_path

    def encode(self):
        """
        加密并生成文件
        :return:
        """
        # 读取文件
        xml_info = self.read_file()
        # 加密文件
        encode_info = BasicMethod().des_encrypt(xml_info.encode("utf-8"))
        # 生成文件
        with open(os.path.join(self.path, "mdm_auto_account_encode.xml"), "w", encoding="utf-8") as f:
            f.write(encode_info)
        return os.path.join(self.path, "mdm_auto_account_encode.xml")

    def read_file(self):
        """
        读取文件
        :return:
        """
        with open(self.encode_path, "r", encoding="utf-8") as f:
            return f.read()
